### to clear data
rm()

### to open a file
datum=read.csv(file.choose())

### view column titles
head (datum)

### need to number results to keep them seperate

install.packages("car")
library(car)

### Factor
datum$Age=as.factor(datum$Age)
datum$Cohort=as.factor(datum$Cohort)
datum$Race=as.factor(datum$Race)
datum$Edu=as.factor(datum$Edu)


---------------------------------------------------------
### unadjusted model
### run an regression with MD Score and cohort
results1=lm(Med_Diet_Total~EB_Score,data=datum)
summary(results1)

--------------------------------------------------------
### model with demographic variables
### white, High_school_lower were the reference groups
results101=lm(Med_Diet_Total ~ EB_Score + Cohort+ Sex+ Age + relevel(Race, ref="White") + relevel(Edu, ref="High_school_lower") + Qual + BMI_Cat, data = datum)
summary(results101)

anova(results1,results101)
Anova(results1, type="III")
Anova(results1, type="3")
Anova(results101, type="3")
Anova(results101, type="III")